<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="support.*, java.util.*, java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>


	<%
	Connection conn = null;
	PreparedStatement pStmt = null;
	ResultSet rs = null;

    // Registering Postgresql JDBC driver with the DriverManager
    Class.forName("org.postgresql.Driver");

    // Open a connection to the database using DriverManager
    conn = DriverManager.getConnection(
        "jdbc:postgresql://localhost/postgres?" +
        "user=postgres&password=cse135");
    
    conn.setAutoCommit(false);

	
	
		support s = new support();   	
		String path4 = config.getServletContext().getRealPath("specializations.txt");
		Vector specializations = s.getSpecializations(path4);
		
		for(int i=0; i<specializations.size(); i++){
			String specialization = (String)specializations.get(i);
	      out.println(specialization+ " ");
	      
	  			int count = 0;
			    Statement stmt = conn.createStatement();
			    Integer app_id = null;
			    Integer add_id = null;
			    Integer deg_id = null;
			    rs = stmt.executeQuery("SELECT app_id from degrees where specialization='"+specialization + "'");
			    while(rs.next()){
			    	//if(rs.getInt(1))
			 	  		count++;
			    }
			      
			    out.println(", Number of applicants: " + "<a href='applications.jsp?specialization=" +specialization+"'>" + count + "</a>");			   
	      out.println("<br>");
	}
		

		//// Commit transaction
		conn.commit();
		conn.setAutoCommit(true);
		//pStmt.close();
		conn.close();
	%>


</body>
</html>